package com.cln.reverse_string;

import junit.framework.TestCase;

public class NewStringReverserTest extends TestCase {
	// "a b" - "b a"
	public void testSimpleReverse() {
		assertEquals("b a", reverse("a b"));
		assertEquals("c b a", reverse("a b c"));
		assertEquals("Tdd is a software devolopment technology", reverse("technology devolopment software a is Tdd"));
	}

	private String reverse(String inputString) {
		String splitToken = " ";
		int tokenIndex = inputString.indexOf(splitToken);
		if (tokenIndex == -1)
			return inputString;
		String prePart = inputString.substring(0, tokenIndex);
		String postPart = inputString.substring(tokenIndex + 1);
		return reverse(postPart) + splitToken + reverse(prePart);
	}

	public void testReverseWithSingleWords() {
		assertEquals("a", reverse("a"));
	}

	public void testReverseWithSplitTokenIn() {
		assertEquals(" ", reverse(" "));
		assertEquals("   ", reverse("   "));
		assertEquals("   a", reverse("a   "));
		assertEquals("b a", reverse("a b"));
		assertEquals("c b a ", reverse(" a b c"));
		assertEquals("c b a", reverse("a b c"));
	}

	// public void testNullReverse(){
	// assert(null, new StringReverser(null).reverse());
	// }

}
